package com.xungou.user.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.xungou.shop.pojo.Shop;
import com.xungou.shop.service.IShopService;
import com.xungou.utils.UserUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xungou.user.pojo.User;
import com.xungou.user.service.IUserService;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/user")
public class UserController {
	@Resource
	private IUserService userService;
	@Resource
	private IShopService shopService;

	@RequestMapping("/index")
	public ModelAndView index(){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("global/index");
		return modelAndView;
	}

	@RequestMapping("/manage")
	public ModelAndView manage(){
		ModelAndView modelAndView = new ModelAndView();
		if(SecurityUtils.getSubject().hasRole("ADMIN"))
			modelAndView.setViewName("global/manage");
		else{
			SecurityUtils.getSubject().logout();
			modelAndView.setViewName("global/login");
		}
		return modelAndView;
	}

	@RequestMapping("/personalCenter")
	public ModelAndView personalCenter(@RequestParam Map<String, String> params){
		if(params.get("page")==null||params.get("page")==null)
			params.put("page","orderListForBuyerPage");
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("page",params.get("page"));
		modelAndView.setViewName("home/personalCenter/personalCenter");
		return modelAndView;
	}

	@RequestMapping("/shopManage")
	public ModelAndView shopManage(){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("home/shopManage/shopManage");
		return modelAndView;
	}

	@RequestMapping("/receiverPage")
	public ModelAndView receiverPage(){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("home/receiverManage/receiverManage");
		return modelAndView;
	}

	@RequestMapping("/addReceiverPage")
	public ModelAndView addReceiverPage(){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("home/receiverManage/addReceiver");
		return modelAndView;
	}

	@RequestMapping("/senderManagePage")
	public ModelAndView senderManagePage(){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("home/senderManage/senderManage");
		return modelAndView;
	}

	@RequestMapping("/addSenderPage")
	public ModelAndView addSenderPage(){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("home/senderManage/addSender");
		return modelAndView;
	}

	@RequestMapping("/shoppingCart")
	public ModelAndView shoppingCart(){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("home/shoppingCart/shoppingCart");
		return modelAndView;
	}

	@RequestMapping("/orderListForBuyerPage")
	public ModelAndView orderListForBuyerPage(){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("home/order/orderListForBuyer");
		return modelAndView;
	}

	@RequestMapping("/orderListForShopPage")
	public ModelAndView orderListForShopPage(){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("home/order/orderListForShop");
		return modelAndView;
	}

}